﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sale.Api.Application.Command.Contract;
using Sale.Dtos;
using Sale.ErrorCode;

namespace Sale.Api.Controllers
{
    /// <summary>
    /// 销售合同控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class ContractController : ControllerBase
    {
        private readonly IMediator mediator;

        public ContractController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 销售合同添加接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddContract(AddContractCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 销售合同显示查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<ContractDTO>> ShowContract([FromQuery]ShowContractCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 销售合同删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> DelContract([FromQuery]DelContractCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 销售合同修改接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateContract(UpdateContractCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
